﻿using System;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Media;
using Microsoft.Xna.Framework.Content;


namespace kompot_wtf
{
    public class Sounds : GameObject
    {

        private static Random Random = new Random();

	
        static SoundEffect waltz;
		static SoundEffectInstance waltzI;

        static SoundEffect helmut;
        static SoundEffectInstance helmutI;

        static SoundEffect menu;
        static SoundEffectInstance menuI;

        static SoundEffect wilhelm ;
        static SoundEffectInstance wilhelmI;

        static SoundEffect steps;
        static SoundEffectInstance stepsI;

        static SoundEffect fanfare;
        static SoundEffectInstance fanfareI;

        static SoundEffect longscream;
        static SoundEffectInstance longscreamI;

        static SoundEffect sonar;
        static SoundEffectInstance sonarI;

        static SoundEffect intro;
        static SoundEffectInstance introI;

        static SoundEffect deathmusic;
        static SoundEffectInstance deathmusicI;

        static SoundEffectInstance [] screams;


        static SoundEffect hit0;
        static SoundEffect hit1;
        static SoundEffect hit2;
        static SoundEffect hit3;
        static SoundEffect hit4;
        static SoundEffect hit5;

        static SoundEffect grunt0;
        static SoundEffect grunt1;
        static SoundEffect grunt2;
        static SoundEffect grunt3;
        static SoundEffect grunt4;
        static SoundEffect grunt5;
        

        
        static SoundEffectInstance[] hits;
        static SoundEffectInstance[] grunts;

        public Sounds(ContentManager Content){

           waltz = Content.Load<SoundEffect>("Sounds//waltz");
           waltzI =  waltz.CreateInstance();

           helmut = Content.Load<SoundEffect>("Sounds//helmut");
           helmutI = helmut.CreateInstance();

           menu = Content.Load<SoundEffect>("Sounds//menu");
           menuI = menu.CreateInstance();

           wilhelm = Content.Load<SoundEffect>("Sounds//wilhelm");
           wilhelmI = wilhelm.CreateInstance();

           steps = Content.Load<SoundEffect>("Sounds//steps");
           stepsI = steps.CreateInstance();

           fanfare = Content.Load<SoundEffect>("Sounds//fanfare");
           fanfareI = fanfare.CreateInstance();

           longscream = Content.Load<SoundEffect>("Sounds//longscream");
           longscreamI = longscream.CreateInstance();


           sonar = Content.Load<SoundEffect>("Sounds//sonar");
           sonarI = sonar.CreateInstance();

           intro = Content.Load<SoundEffect>("Sounds//intro");
           introI = intro.CreateInstance();

           deathmusic = Content.Load<SoundEffect>("Sounds//deathmusic");
           deathmusicI = deathmusic.CreateInstance();

           screams = new SoundEffectInstance[3];
           screams[0] = helmutI;
           screams[1] = wilhelmI;
           screams[2] = longscreamI;

           hits = new SoundEffectInstance[6];

           hit0 = Content.Load<SoundEffect>("Sounds//hit0");
           hits[0] = hit0.CreateInstance();

           hit1 = Content.Load<SoundEffect>("Sounds//hit1");
           hits[1] = hit1.CreateInstance();

           hit2 = Content.Load<SoundEffect>("Sounds//hit2");
           hits[2] = hit2.CreateInstance();

           hit3 = Content.Load<SoundEffect>("Sounds//hit3");
           hits[3] = hit3.CreateInstance();

           hit4 = Content.Load<SoundEffect>("Sounds//hit4");
           hits[4] = hit4.CreateInstance();

           hit5 = Content.Load<SoundEffect>("Sounds//hit5");
           hits[5] = hit5.CreateInstance();




           grunts = new SoundEffectInstance[6];

           grunt0 = Content.Load<SoundEffect>("Sounds//grunt0");
           grunts[0] = grunt0.CreateInstance();

           grunt1 = Content.Load<SoundEffect>("Sounds//grunt1");
           grunts[1] = grunt1.CreateInstance();

           grunt2 = Content.Load<SoundEffect>("Sounds//grunt2");
           grunts[2] = grunt2.CreateInstance();

           grunt3 = Content.Load<SoundEffect>("Sounds//grunt3");
           grunts[3] = grunt3.CreateInstance();

           grunt4 = Content.Load<SoundEffect>("Sounds//grunt4");
           grunts[4] = grunt4.CreateInstance();

           grunt5 = Content.Load<SoundEffect>("Sounds//grunt5");
           grunts[5] = grunt0.CreateInstance();

        }



       public static void play_waltz()
        {
            waltzI.Play();
        }

       public static void pause_waltz()
       {
           waltzI.Pause();
       }

       public static void play_helmut()
       {
           helmutI.Play();
       }

       public static void play_menu()
       {
           menuI.Play();           
       }

       public static void pause_menu()
       {
           menuI.Pause();
       }



       public static void play_wilhelm()
       {
           wilhelmI.Play();
       }

       public static void play_steps()
       {
           stepsI.Play();
       }

       public static void pause_steps()
       {
           stepsI.Pause();
       }

       public static void play_fanfare()
       {
           fanfareI.Play();
       }

       public static void play_longscream()
       {
           longscreamI.Play();
       }


       public static void play_randomscream()
       {
           int id = 999;

           while (id > 2)
           {
            
               id = Convert.ToInt32(Random.NextDouble() * 10);
               
           }
           System.Console.WriteLine(id.ToString());
           screams[id].Play();

       }


       public static void play_randomgrunt()
       {
           int id = 999;

           while (id > 5)
           {

               id = Convert.ToInt32(Random.NextDouble() * 10);

           }
           System.Console.WriteLine(id.ToString());
           grunts[id].Play();

       }


       public static void play_randomhit()
       {
           int id = 999;

           while (id > 5)
           {

               id = Convert.ToInt32(Random.NextDouble() * 10);

           }
           System.Console.WriteLine(id.ToString());
           hits[id].Play();

       }


       public static void play_sonar()
       {
           sonarI.Play();
       }


       public static void play_intro()
       {
           introI.Play();
       }

       public static void stop_intro()
       {
           introI.Stop();
       }

       public static void stop_menu()
       {
           menuI.Stop();
       }

       public static void play_deathmusic()
       {
           deathmusicI.Play();
       }

	   public static void stop_deathmusic() {
		   deathmusicI.Stop();
	   }

       public static bool is_fanfare_playing()
       {
           if (fanfareI.State != SoundState.Playing)
           {
               return false;
           }

           return true;
       }
    }
}
